/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-02-24     86188       the first version
 */
#include "head_rtthread.h"
#include "head_user.h"

/*===========================================================================*/
G_ioHandleTypedef   G_ioHandle;
/*===========================================================================*/
static void io_init(void)
{
        /* set on-board led as push-pull output*/
        rt_pin_mode(led_Red,    PIN_MODE_OUTPUT);
        rt_pin_mode(led_Green,  PIN_MODE_OUTPUT);
        rt_pin_mode(led_Blue,   PIN_MODE_OUTPUT);
        rt_pin_mode(led_Yellow, PIN_MODE_OUTPUT);

        /* set the initial state of led to be on */
        rt_pin_write(led_Red,       PIN_LOW);
        rt_pin_write(led_Green,     PIN_LOW);
        rt_pin_write(led_Blue,      PIN_LOW);
        rt_pin_write(led_Yellow,    PIN_LOW);

}

static void g_io_high(uint8_t ID)
{
    rt_pin_write(ID, PIN_HIGH);
}
static void g_io_low(uint8_t ID)
{
    rt_pin_write(ID, PIN_LOW);
}
static void g_io_toggle(uint8_t ID)
{
    rt_pin_write(ID, !rt_pin_read(ID));
}

static int g_io_init(void)
{
    io_init();

    G_ioHandle.high     = g_io_high;
    G_ioHandle.low      = g_io_low;
    G_ioHandle.toggle   = g_io_toggle;
    return 0;
}

/* automatic initialization */
INIT_BOARD_EXPORT(g_io_init);
